﻿package Classes{
	import flash.display.*;
	import flash.events.*;
	
	import Classes.Utils.*;
	import Classes.*;
	import Classes.Layers.*;
	
	//场景中所有可移动物体的基类
	public class BasicElement extends MovieClip{
		//场景移动速度
		public var stagespeed:Number = GameSettings.stagespeed;;
		//是否可清除
		public var erasable:Boolean;
		//是否可移动
		public var moveable:Boolean;		
		//移动速度
		public var speed:Number;
		//移动范围
		public var moverange:Array;
		//是否可爆炸
		public var explodeable:Boolean;
		//爆炸类型
		public var explodeType:int;
		//所在层
		public var dimension:Layer;
		//构造函数
		public function BasicElement(){
			erasable = false;			
			explodeable = false;
			moverange = [0,GameSettings.sceneWidth,0,GameSettings.sceneHeight];
			//用弱引用的方式添加事件侦听器
			addEventListener(Event.ENTER_FRAME,onEnterFrame,false,0,true);
		}
		//当播放桢时执行move方法
		protected function onEnterFrame(e:Event):void{
			if(isInRange())
				move();
		}		
		//是否在可移动范围内
		protected function isInRange():Boolean{
			if(!moverange)
				return true;
			if(this.x>=moverange[0] && this.x<=moverange[1] && this.y>=moverange[2] && this.y<=moverange[3]){
				return true;
			}else{								
				parent.setChildIndex(this,0);
				erasable = true;
				return false;
			}
		}
		//移动
		protected function move():void{
		}
		//清除事件侦听器
		public function remove():void{
			removeEventListener(Event.ENTER_FRAME,onEnterFrame);
		}		
	}
}